package com.iocup.keybastion.authorize.element;


import com.iocup.keybastion.utils.PathUtil;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 配置文件的权限元素提供者
 * @Author: xyjxust
 * @Date: 2022/3/22 13:51
 */
public class ConfigFileElementProvider implements AuthElementProvider {

    @Getter
    private AuthElementStore elementStore = new InMemoryAuthElementStore();

    /**
     * 路径匹配工具
     */
    private PathUtil pathUtil = new PathUtil();


    @Override
    public List<AuthElement> getAuthElement() {
        return elementStore.getAll();
    }

    @Override
    public List<AuthElement> getAuthElement(String key) {
        List<AuthElement> elements = getAuthElement();
        return elements.stream().filter(el->pathUtil.match(el.getCode(),key)).collect(Collectors.toList());
    }
}
